import axios, { AxiosInstance } from 'axios'
import { type Config, CrawlerFileUtils, getRandomIP, getRandomUserAgent } from '../../utils/baseUtils.js'

export interface PageAttributes {
  [key: string]: number | undefined; // 假设所有属性都是number或undefined，根据实际情况可以调整
}
export interface LastPageMap {
  [key: string]: PageAttributes; // 每个键对应一个属性集
}
export interface LastTokenMap {
  [key: string]: string; // 每个键对应一个token
}

type ConfigCanvasPhoto = Config & {
  lastTokenMap:LastTokenMap // 保存上一次的token
  lastPageMap:LastPageMap // 保存上一次的page
}
const fileUtils = new CrawlerFileUtils< ConfigCanvasPhoto >(import.meta.url);


const axiosInstance: AxiosInstance = axios.create({
    timeout: 10000, // 10秒超时
  })
  axiosInstance.interceptors.request.use((config) => {
    config.headers['User-Agent'] = getRandomUserAgent()
    config.headers['X-Forwarded-For'] = getRandomIP()
    config.headers['X-Real-IP'] = getRandomIP()
    config.headers['Referer'] = 'https://www.canva.cn/'
    return config
  })

export { axiosInstance, fileUtils, }